package com.xindz.hgq.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;

import com.blankj.utilcode.util.ToastUtils;
import com.kingja.loadsir.callback.Callback;
import com.xindz.hgq.R;
import com.xindz.hgq.base.BaseActivity;
import com.xindz.hgq.base.options.BaseActivityOptions;

import java.util.concurrent.TimeUnit;

import butterknife.ButterKnife;
import io.reactivex.Observable;
import io.reactivex.functions.Consumer;

/**
 * @name HGQBase
 * @class name：com.xindz.hgq.activity
 * @describe 使用Loadsir模式开发需要进行一下操作
 * 一 AppLocation中初始化LoadSir LoadSir.beginBuilder().addCallback(new XXXCallback()).setDefaultCallback(new XXXCallback())commit;
 * 二 实现Callback.OnReloadListener接口
 * 三 在setOption方法返回Options 并开启LoadSir new BaseActivityOptions().openLoadSir(this)
 * 四 BaseActivity中封装了公共的对页面状态操作方法如showLoadSirSuccess()
 * @anthor XINDZ
 * @time 2018/1/16 10:15
 * @change
 * @chang time
 * @class describe
 */
public class LoadSirActivity extends BaseActivity implements Callback.OnReloadListener {
    @Override
    public BaseActivityOptions setOption() {
        return new BaseActivityOptions().openLoadSir(this);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_act_loadsir);

        Observable.timer(2, TimeUnit.SECONDS)
                .subscribe(new Consumer<Long>() {
                    @Override
                    public void accept(Long aLong) throws Exception {
                        showLoadSirError();
                    }
                });
    }

    @Override
    public void onReload(View v) {
        ToastUtils.showShort("ReLoad");
        showLoadSirSuccess();

    }
}
